
local MainScene = class("MainScene", function()
    return display.newScene("MainScene")
end)

function MainScene:ctor()
    --[[cc.ui.UILabel.new({
            UILabelType = 2, text = "Hello, World", size = 64})
        :align(display.CENTER, display.cx, display.cy)
        :addTo(self)
    --]]
    local buy = display.newSprite("buy.png",display.cx,display.cy)
    self:addChild(buy)
    
    local vo = {}
    vo.title = "金币"
    vo.content = "购买金币"
    vo.money = 0.01   
    
    local function alipCallBack( dataString )
        dump("java 回调 lua ")
        local alipayTimes = 0
        dump(dataString)
        dump(type(dataString))
        if type(dataString) == "string" then
        --buyProxy.aliPayResult(dataString,vo)
        --    dump("callback!")        
            if dataString == "true" then
                dump("java 回调 lua  ,lua 接收到付款成功的消息！")
            elseif dataString == "waiting" then
                dump("java 回调 lua  ,lua 接收到付款等待的消息！")
            else
                dump("java 回调 lua  ,lua 接收到付款失败的消息！")
            end
        end
    end      
    
    local function back( --[[returnData--]] )
        if device.platform == "android" then
            --[[local args = {
                tostring(returnData.data.billid),
                "天天弹钢琴",
                "购买钻石 X"..vo.diamond,
                vo.money,
                alipCallBack

            }
            local alipayBillId = returnData.data.billid
            local sig = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)Z"
            local AliPayClass = "com/funhappy/game/piano/QLALiPay"
            local ok, ret = luaj.callStaticMethod(AliPayClass, "payAli", args,sig)
            if ok then
                print("getIsValid,ret:",ret)
                return ret`
            else
                print("shareEvent error code = ", ret)
            end
            --]]
            local args = {
                vo.title,
                vo.content,        
                vo.money,
                alipCallBack
            }
            local sig = "(Ljava/lang/String;Ljava/lang/String;FI)V"
            local AliPayClass = "org/cocos2dx/alipay/Alipay"    
            local ok, ret = luaj.callStaticMethod(AliPayClass, "pay", args,sig)
            dump(ok)
            dump(ret)
            if ok then
                print("getIsValid,ret:",ret)
                return ret
            else
                print("shareEvent error code = ", ret)
            end
        end
    end
    --local msg = { productid = vo.pID}
    --NetUtil.postHttp(GAME_SERVER.."c=alipay&m=get_billid",back,msg)
        
    buy:setTouchEnabled(true)
    buy:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
        if event.name == "began" then
        elseif event.name == "moved" then
        else
            dump("ended")         
            back()
        end
        return true
    end)   
end

function MainScene:onEnter()
end

function MainScene:onExit()
end

return MainScene
